<template>
  <div class="app-container">
    <el-form ref="formRef" :model="form" label-width="100px">
      <el-row :gutter="20">
        <el-col :span="6">
          <el-form-item label="工段编号" prop="workshopCode">
            {{ form.workshopCode }}
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="工段名称" prop="workshopName">
            {{ form.workshopName }}
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="工段类型" prop="workshopType">
            <dict-tag :options="workshop_type" :value="form.workshopType" />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="工厂" prop="workshopType">
            {{ form.factoryName }}
          </el-form-item>
        </el-col>

        <el-col :span="6">
          <el-form-item label="工段长" prop="headUserName">
            {{ form.headUserName }}
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="副工段长" prop="deputyUserName">
            {{ form.deputyUserName }}
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <!-- <el-form-item label="备注" prop="remark">
            {{ form.remark }}
          </el-form-item> -->
          <el-form-item label="备注" prop="remark">
            <el-tooltip class="box-item" effect="dark" :content="form.remark" placement="top-start">
              <p style=" margin: 0;overflow: hidden; text-overflow: ellipsis; white-space: nowrap">
                {{ form.remark }}
              </p>
            </el-tooltip>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>

    <el-tabs v-model="activeName" class="demo-tabs">
      <el-tab-pane label="包含产线" name="first"></el-tab-pane>
      <el-form
        :model="queryParams"
        ref="queryRef"
        :inline="true"
        v-show="showSearch"
        label-width="100px"
      >
        <el-form-item label="产线名称" prop="name">
          <el-input
            v-model="queryParams.name"
            placeholder="请输入产线名称"
            clearable
            style="width: 240px"
            @keyup.enter="handleQuery"
          />
        </el-form-item>

        <el-form-item>
          <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
          <el-button icon="Refresh" @click="resetQuery">重置</el-button>
        </el-form-item>
      </el-form>
      <el-row :gutter="10" class="mb8">
        <right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
      </el-row>

      <el-table v-loading="loading" border :data="tableData">
        <el-table-column type="selection" width="55" align="center" />
        <el-table-column
          label="产线编号"
          align="center"
          prop="code"
          :show-overflow-tooltip="true"
        />
        <el-table-column
          label="产线名称"
          align="center"
          prop="name"
          :show-overflow-tooltip="true"
        />

        <el-table-column
          label="产线负责人"
          align="center"
          prop="ownerName"
          :show-overflow-tooltip="true"
        />
      </el-table>

      <pagination
        v-show="total > 0"
        :total="total"
        v-model:page="queryParams.pageNum"
        v-model:limit="queryParams.pageSize"
        @pagination="getList"
      />
    </el-tabs>
  </div>
</template>

<script setup name="Data">
import { getWorkshop } from "@/api/base/workshop";
import { listPage } from "@/api/base/prodLine";
import { ref, reactive, toRefs, useAttrs, onMounted, getCurrentInstance } from "vue";
const { proxy } = getCurrentInstance();
const showSearch = ref(true);
const { workshop_type } = proxy.useDict("workshop_type");
const attrs = useAttrs();
const data = reactive({
  form: {},
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    userName: undefined,
  },
});
const tableData = ref([]);
const activeName = ref("first");
const total = ref(0);
const formRef = ref(null);
const { form, queryParams } = toRefs(data);

function getDetail(id) {
  reset();
  getWorkshop(id).then((res) => {
    form.value = res.data;
    queryParams.value.workshopCode = form.value.workshopCode;
    getList();
  });
}

function getList() {
  listPage(queryParams.value).then((response) => {
    tableData.value = response.rows;
    total.value = response.total;
  });
}

/** 搜索按钮操作 */
function handleQuery() {
  queryParams.value.pageNum = 1;
  getList();
}

/** 重置按钮操作 */
function resetQuery() {
  proxy.resetForm("queryRef");
  handleQuery();
}

/** 表单重置 */
function reset() {
  form.value = {
    name: undefined,
    type: undefined,
    equipNo: undefined,
    model: undefined,
    factory: undefined,
    segmentCode: undefined,
    workshopCode: undefined,
    status: undefined,
    remark: undefined,
  };
  formRef.value.resetFields();
}
onMounted(async () => {
  const { data } = attrs;
  getDetail(data.id);
});
</script>
